package org.andy.shop.controller;


import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.andy.shop.model.Menu;
import org.andy.shop.service.MenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

@Controller
@RequestMapping(value="/menu",produces="application/json;charset=UTF-8")
public class MenuController {

	@Resource
	private MenuService menuService;
	
	
	@GetMapping("/list")
	@ResponseBody
	private String list(HttpServletRequest request) {
		JSONObject json = new JSONObject();
		List<Menu> menus = menuService.getMenus();
		json.put("result", true);
		json.put("menus", menus.toArray());
		return json.toJSONString();
	}
	
	@GetMapping("/getList")
	@ResponseBody
	private String getList(HttpServletRequest request) {
		JSONObject json = new JSONObject();
		System.out.println(request.getParameter("page"));
		System.out.println(request.getParameter("limit"));
		List<Menu> menus = menuService.getMenus();
		json.put("count", menus.size());
		json.put("data", menus);
		json.put("code", 0);
		json.put("msg", "");
		return json.toJSONString();
	}
}
